package com.octopus.optiworks.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Command binding object for search products.
 */
public class SearchCommand {

    private String finalSn;
    
    private String internalSn;
    
    private String pn;
    
    private String step;
    
    private String operator;
    
    private List<String> permissons;
    
    private String keyword;
    
    private String beginDateStr;
    
    private String endDateStr;
    
    private Date beginDate;
    
    private Date endDate;
    
    private Boolean archive = false;
    
    private Integer total = 0;
    
    private Integer offset = 0;
    
    private Integer length = 10;
    
    private Integer pageIndex = 5;
    
    public SearchCommand(){
    	ResourceBundle configuation = ResourceBundle.getBundle("configuration", Locale.getDefault());
		try{
			String lenght = configuation.getString("page.item.size");
			String pageIndex = configuation.getString("page.index.size");
			if(lenght != null){
				this.setLength(new Integer(lenght));
			}
			if(pageIndex != null){
				this.setPageIndex(new Integer(pageIndex));
			}
		}catch(MissingResourceException e){
		}
    }
    
    public void clear(){
    	this.finalSn = null;
    	this.internalSn = null;
    	this.pn = null;
    	this.step = null;
    	this.permissons = null;
    	this.keyword = null;
    	this.operator = null;
    	this.archive = false;
    }
    
    public void copy(SearchCommand command){
    	this.finalSn = command.getFinalSn();
    	this.internalSn = command.getInternalSn();
    	this.pn = command.getPn();
    	this.step = command.getStep();
    	this.permissons = command.getPermissons();
    	this.keyword = command.getKeyword();
    	this.operator = command.getOperator();
    	this.archive = command.getArchive();
    }

	public String getFinalSn() {
		return finalSn;
	}

	public void setFinalSn(String finalSn) {
		this.finalSn = finalSn;
	}

	public String getInternalSn() {
		return internalSn;
	}

	public void setInternalSn(String internalSn) {
		this.internalSn = internalSn;
	}

	public String getPn() {
		return pn;
	}

	public void setPn(String pn) {
		this.pn = pn;
	}

	public String getStep() {
		return step;
	}

	public void setStep(String step) {
		this.step = step;
	}

	public List<String> getPermissons() {
		return permissons;
	}

	public void setPermissons(List<String> permissons) {
		this.permissons = permissons;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public Integer getOffset() {
		return offset;
	}

	public void setOffset(Integer offset) {
		this.offset = offset;
	}

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getBeginDateStr() {
		return beginDateStr;
	}

	public void setBeginDateStr(String beginDateStr) {
		this.beginDateStr = beginDateStr;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", new Locale("en"));
		if(beginDateStr != null && beginDateStr.trim().length() > 0)
			try {
				this.beginDate = format.parse(beginDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
	}

	public String getEndDateStr() {
		return endDateStr;
	}

	public void setEndDateStr(String endDateStr) {
		this.endDateStr = endDateStr;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", new Locale("en"));
		if(endDateStr != null && endDateStr.trim().length() > 0)
			try {
				this.endDate = format.parse(endDateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
	}

	public Boolean getArchive() {
		return archive;
	}

	public void setArchive(Boolean archive) {
		this.archive = archive;
	}

}
